package com.meta.platform.area.repository;

import com.google.common.collect.Lists;
import com.meta.platform.area.define.AreaStatusEnum;
import com.meta.platform.area.domain.Areas;
import com.meta.platform.area.io.Province;
import com.meta.platform.area.mapper.AreasMapper;
import com.meta.platform.area.req.ro.AreasRo;
import com.meta.framework.define.DelFlagEnum;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 地区信息
 *
 * @Title: AreasRepositoryImpl
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2020-07-14 18:05:05
 * @Version: v2.0
 */
@Service
public class AreasRepositoryImpl implements AreasRepository {

	private AreasMapper areasMapper;

	public AreasRepositoryImpl(AreasMapper areasMapper) {
		this.areasMapper = areasMapper;
	}

	/**
	 * insert Areas info
	 *
	 * @param areas:
	 * @return void
	 * @method insertAreas
	 * @author M.simple
	 * @date 2020-07-14 18:05:05
	 */
	@Override
	public void insertAreas(Areas areas) {
		areasMapper.insertAreas(areas);
	}

	/**
	 * batch insert Areas info
	 *
	 * @param areasses:
	 * @return void
	 * @method insertAreas
	 * @author M.simple
	 * @date 2020-07-14 18:05:05
	 */
	@Override
	public void batchInsertAreas(List<Areas> areasses) {
		areasMapper.batchInsertAreas(areasses);
	}

	/**
	 * update Areas info
	 *
	 * @param areas:
	 * @return int
	 * @method updateAreas
	 * @author M.simple
	 * @date 2020-07-14 18:05:05
	 */
	@Override
	public int updateAreas(Areas areas) {
		return areasMapper.updateAreas(areas);
	}

	/**
	 * update Areas info by Pk
	 *
	 * @param areas:
	 * @return int
	 * @method updateAreasByPk
	 * @author M.simple
	 * @date 2020-07-14 18:05:05
	 */
	@Override
	public int updateAreasByPk(Areas areas) {
		return areasMapper.updateAreasByPk(areas);
	}

	/**
	 * list Areas info
	 *
	 * @param areasRo:
	 * @return List<Areas>
	 * @method listAreas
	 * @author M.simple
	 * @date 2020-07-14 18:05:05
	 */
	@Override
	public List<Areas> listAreas(AreasRo areasRo) {
		areasRo.setOutAreastatusList(Lists.newArrayList(AreaStatusEnum.DEFAULT_CREATE.getCode()));
		areasRo.setDelFlag(DelFlagEnum.O.getCode());
		return areasMapper.listAreas(areasRo);
	}

	/**
	 * list Areas info
	 *
	 * @param areasRo:
	 * @return List<Areas>
	 * @method listAreas
	 * @author M.simple
	 * @date 2020-07-14 18:05:05
	 */
	@Override
	public List<Areas> listEffectiveAreas(AreasRo areasRo) {
		areasRo.setAreaStatus(AreaStatusEnum.EFFECTIVE.getCode());
		areasRo.setDelFlag(DelFlagEnum.O.getCode());
		return areasMapper.listAreas(areasRo);
	}

	/**
	 * get province Id
	 *
	 * @param areaId:
	 * @return Areas
	 * @method geAreas
	 * @author M.simple
	 * @date 2020/7/31 2:14 下午
	 * @version v2.0
	 */
	@Override
	public Areas getAreas(Long areaId) {

		AreasRo areasRo = AreasRo.builder().build();
		areasRo.setAreaId(areaId);
		List<Areas> areasList = areasMapper.listAreas(areasRo);
		if (CollectionUtils.isNotEmpty(areasList)) {
			return areasList.get(0);
		}
		return null;
	}

	@Override
	public List<Long> queryFullAreaId(Long areaId) {
		return null;
	}

	@Override
	public List<Areas> queryAllArea() {
		return listAreas(AreasRo.builder().build());
	}

	@Override
	public void insertAreaExpa(List<Map<String, Object>> areaMapList) {

	}

	@Override
	public List<Province> queryAddress() {
		return null;
	}

}
